<template>
  <div>
    <a-button class="editable-add-btn" @click="directToAddPage">Add</a-button>
    <a-table bordered :dataSource="dataSource" :columns="columns"></a-table>
  </div>
</template>

<script>
import * as api from '@/api'
export default {
  data () {
    return {
      dataSource: [],
      columns: [
        {
          title: 'ID',
          dataIndex: 'id'
        },
        {
          title: '分类',
          dataIndex: 'category_name'
        },
        {
          title: '品牌',
          dataIndex: 'brand_name'
        },
        {
          title: '商品名称',
          dataIndex: 'goods_name'
        },
        {
          title: '售价',
          dataIndex: 'sell_price'
        },
        {
          title: '已出售',
          dataIndex: 'sale_count'
        }
      ]
    }
  },
  mounted () {
    api.getGoodsList().then(response => {
      this.dataSource = response.data.map(e => {
        e.key = e.id
        return e
      })
    })
  },
  methods: {
    directToAddPage () {
      this.$router.push('/shop/add')
    }
  }
}
</script>

<style>
</style>
